package bookticket.crm.recharge.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import bookticket.crm.recharge.dao.RechargeDao;
import bookticket.crm.recharge.entity.RechargeEntity;
import bookticket.crm.recharge.service.RechargeService;
import bookticket.crm.user.dao.UserDao;
import bookticket.crm.user.entity.UserEntity;


@Service
public class RechargeServiceImpl implements RechargeService {

	@Autowired
	private RechargeDao dao;
	
	@Autowired 
	private UserDao userDao;
	
	@Override
	public int add(RechargeEntity entity) {
		return dao.add(entity);
	}
	
	@Override
	public List<RechargeEntity> findAll(Map<String, Object> pageMap) {
		return dao.findAll(pageMap);
	}

	@Override
	public int getTotalCounter(String phone) {
		return dao.getTotalCounter(phone);
	}
	
	public int updateUserByPhone(UserEntity userEntity){
		return userDao.updateByPhone(userEntity);
		
	}

	public UserEntity findUserByPhone(String phone) {
		return userDao.findByPhone(phone);
	}

	@Override
	public int findUserTotalRecharge() {
		int totalAmount = 0;
		Map<String, Object> pageMap = null;
		List<RechargeEntity> entity = dao.findAll(pageMap);
		for (RechargeEntity recharge : entity) {
			int everyAmount = recharge.getRechargeAmount();
			totalAmount += everyAmount;
		}
		System.err.println(totalAmount);
		return totalAmount;
	}

}
